<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<#include "../inc/commonJs.html">
<title>栏目管理</title>
<script type="text/javascript">
	// 定义标题栏
	var columns = [ [ {
		field : 'id',
		title : '栏目ID',
		width : '60',
		align : 'center'
	}, {
		field : 'name',
		title : '栏目名称',
		width : '80',
		align : 'center'
	}, {
		field : 'content',
		title : '栏目说明',
		width : '80',
		align : 'center'
	}, {
		field : 'fview',
		title : '前台显示',
		align : 'center',
		width : '80',
		formatter:function(value,row,index){
			if(value==1){
				return '显示';
			}else{
				return '隐藏';
			}
		}
	}, {
		field : 'bview',
		title : '后台显示',
		align : 'center',
		width : '80',
		formatter:function(value,row,index){
			if(value==1){
				return '显示';
			}else{
				return '隐藏';
			}
		}
	}, {
		field : 'mode',
		title : '显示模板',
		align : 'center',
		width : '120',
		formatter:function(value,row,index){
			if(value==1){
				return '新闻媒体模板';
			}else{
				return '单独页面模板';
			}
		}
	}, {
		field : 'px',
		title : '排序',
		width : '40',
		align : 'center'
	}, {
		field : 'url',
		title : '链接',
		width : '160',
		align : 'center'
	}, {
		field : 'zt',
		title : '状态',
		width : '40',
		align : 'center'
	} ]];
	var grid,typeid;
	//
	$(function(){
		//
		$('#lanmutree').tree({
			url:'typeLeftTree.do',
		    lines:true,
		    animate:true,
		    onClick: function(node){
		    	typeid = node.id;
		    	$('#grid').datagrid({
		    		url : "selectType.do?fid="+node.id
		    	});
			}
		}); 
		//
		$('#typeWindow').dialog({
	        title: '查看栏目',
	        width: 450,
	        modal: true,
	        shadow: true,
	        closed: true,
	        onClose:function(){
	        	$('#id').val('');
	        	$('#name').val('');
	        	$('#content').val('');
	        	$('#url').val('');
	        },
	        buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					$('#typeForm').form('submit', {  
					    url:'saveType.do',
					    onSubmit: function(param){
					    	var isValid = $(this).form('validate');
							return isValid;
					    },
					    success:function(data){
					    	$("#typeWindow").dialog('close');
					    	$('#lanmutree').tree('reload');
					    	grid.datagrid('reload');
					    	grid.datagrid('uncheckAll');
					    	top.messagershow(data);
					    }    
					}); 
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$("#typeWindow").dialog('close');
				}
			}]
	    });
		//
		grid = $('#grid').datagrid( {
			iconCls : 'icon-tip',
			//fitColumns:true,
			striped : true,
			singleSelect:true,
			rownumbers : true,
			pagination : true,
			url : "selectType.do?fid="+${fid!"0"},
			loadMsg : '数据装载中......',
			pageSize:[${syscfg.pageSize!10}],
			pageList: [${syscfg.pageList!10}],
			toolbar : [btn_add,btn_edit,btn_del,"-"],
			idField : 'id', 
			//frozenColumns : frozenColumns,
			columns : columns,
			onClickRow : onClickRow,
			onDblClickRow : doDblClickRow
		});
		
	});
	// 双击
	function doDblClickRow(rowIndex, rowData) {
	}
	// 单击
	function onClickRow(rowIndex, rowData){
	}
	
	function doAdd() {
		$("#typeWindow").dialog('open').dialog('center');
		//alert(typeid);
    	$("#fid").combotree('setValue',typeid);
	}

	function doEdit() {
		var item = grid.datagrid('getSelected');
		if(item!=null){
			$('#typeForm').form('load','selectOneType.do?typeid='+item.id);
			$("#typeWindow").dialog('open').dialog('center');
		}else{
			$.messager.alert("信息提示","请选择相关数据进行操作！","error");
		}
	}

	function doDel() {
		var item = grid.datagrid('getSelected');
		if(item== null){
			$.messager.alert("信息提示","请选择相关数据进行操作！","error");
			return ;
		}
		$.messager.confirm("操作提示", "删除栏目！",function(r){
			if(r){
				 $.post("delType.do", {typeid :item.id}, function(data){
					 if(data){
							top.messagershow(data);
							grid.datagrid('reload');
							$('#lanmutree').tree('reload');
							//grid.datagrid('uncheckAll'); // 取消所有元素选中效果
						}
				});  
			}
		});
	}
	//
</script>	
</head>
<body>
<div align="center" class="easyui-panel" data-options='fit:true,border:false'>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'west',iconCls:'icon-mini-add',title:'栏目列表',border:true,split:true" style="width: 220px;">
		<ul id="lanmutree" class="easyui-tree"></ul>  
	</div>
	<div region="center" border="false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
	<!-- 窗口 -->
	<div  id="typeWindow" style="display:">
		<form id="typeForm" method="post">
			<table class="table_all" align="center" border="0" cellspacing="0" width="99%" cellpadding="0" >
				<tr>
					<input class="easyui-validatebox" type="hidden" id="id" name="id" />
					<td class="td_table_1">栏目名称:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="name" name="name" data-options="required:true"/></td>
				</tr>
				<tr>
					<td class="td_table_1">栏目说明:</td>
					<td class="td_table_2"><textarea class="easyui-validatebox" id="content" name="content" rows="5" cols="35"></textarea></td>
				</tr>
				<tr>
					<td class="td_table_1">上级栏目:</td>
					<td class="td_table_2"><select id="fid"  name="fid" class="easyui-combotree" style="width:200px;"  data-options="url:'alltypeTree.do',multiple:false"></select></td>
				</tr>
				
				<tr>
					<td class="td_table_1">前台显示:</td>
					<td class="td_table_2">
						<select id="fview" class="easyui-combobox" name="fview" style="width:150px;">   
						    <option value="1" checked>显示</option>   
						    <option value="0">隐藏</option>   
						</select> 
					</td>
				</tr>
				<tr>
					<td class="td_table_1">后台显示:</td>
					<td class="td_table_2">
						<select id="bview" class="easyui-combobox" name="bview" style="width:150px;">  
						    <option value="1" checked>显示</option>   
						    <option value="0">隐藏</option>   
						</select> 
					</td>
				</tr>
				<tr>
					<td class="td_table_1">总栏模板:</td>
					<td class="td_table_2">
						<select id="mode" class="easyui-combobox" name="mode" style="width:150px;">   
						    <option value="1" checked>新闻媒体模板</option>   
						    <option value="2">单独页面模板</option>   
						</select> 
					</td>
				</tr>
				<tr>
					<td class="td_table_1">外部链接:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="url" name="url" size="35"/></td>
				</tr>
				<tr>
					<td class="td_table_1">排序:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="px" name="px" value="0" /></td>
				</tr>
				<tr>
					<td class="td_table_1">状态:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="zt" name="zt" value="1" /></td>
				</tr>
			</table>
		</form>
	</div>
</div>
</div>
</body>
</html>